package com.sdkj.action.service;

import java.io.Serializable;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

import net.sf.json.JSONObject;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.sdkj.Entity.service.Introduce;
import com.sdkj.action.base.BaseAction;
import com.sdkj.service.service.IIntroduceService;
import com.sdkj.utils.CommonUtils;

@Controller
@Scope("prototype")
public class IntroduceAction extends BaseAction<Introduce, IIntroduceService> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	public void save() throws SQLException{
		Serializable s=service.save(model);
		JSONObject res=new JSONObject(); 
		if(s!=null){  
			res.put(RES_CODE, 100);
			res.put(RES_MSG, "保存成功"); 
			res.put("id", s);
		}else{
			res.put(RES_CODE, -100);
			res.put(RES_MSG, "保存失败");
		}
		CommonUtils.writeJson(res);
	}
	
	public void details(){
		String hql=" from Introduce where uuid = :id";
		Map<String,Object>params=new HashMap<String,Object>();
		
		params.put("id", model.getUuid());
		
		JSONObject res=new JSONObject();
		
		try {
			Introduce introduce=service.findByHql(hql, params); 
			res.put(RES_CODE, 100);
			res.put(RES_MSG, "查询成功");
			res.put("data", introduce);
			  
		} catch (SQLException e) {
			e.printStackTrace();
			res.put(RES_CODE, -100);
			res.put(RES_MSG, "查询失败");
		}
		CommonUtils.writeJson(res);
	}
	
	public void update() throws SQLException{
		Serializable s=service.update(model);
		JSONObject res=new JSONObject(); 
		if(s!=null){  
			res.put(RES_CODE, 100);
			res.put(RES_MSG, "修改成功");
			res.put("id", s);
		}else{
			res.put(RES_CODE, -100);
			res.put(RES_MSG, "修改失败"); 
		}
		CommonUtils.writeJson(res);
	}
	
	

}
